﻿/*********************************************************************************/
/**    Sims3Pack Readme Generator                                               **/
/**    Copyright (C) 2012  Anja Knackstedt                                      **/
/**                                                                             **/
/**    This program is free software: you can redistribute it and/or modify     **/
/**    it under the terms of the GNU General Public License as published by     **/
/**    the Free Software Foundation, either version 3 of the License, or        **/
/**    (at your option) any later version.                                      **/
/**                                                                             **/
/**    This program is distributed in the hope that it will be useful,          **/
/**    but WITHOUT ANY WARRANTY; without even the implied warranty of           **/
/**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            **/
/**    GNU General Public License for more details.                             **/
/**                                                                             **/
/**    You should have received a copy of the GNU General Public License        **/
/**    along with this program.  If not, see <http://www.gnu.org/licenses/>.    **/
/**                                                                             **/
/*********************************************************************************/




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using Sims3PackReadmeGenerator.Layout;
using Sims3PackReadmeGenerator.language;

namespace Sims3PackReadmeGenerator.Gui
{
    /// <summary>
    /// form for editing the different layouts in a layout collection
    /// displays all available layout collections
    /// new custom collections can be created and deleted
    /// </summary>
    public partial class EditReadmeLayoutGui : Form
    {
        #region events

        public delegate void EditReadmeFormEventHandler(object sender, EventArgs e);
        public event EditReadmeFormEventHandler OnUpdateLayoutHandler;
        public event EditReadmeFormEventHandler OnFormClosingHandler;
        public event EditReadmeFormEventHandler OnUpdateLayoutCollectionsHandler;

        
        /// <summary>
        /// send new layout event
        /// </summary>
        protected void OnLayoutUpdate()
        {
            if (OnUpdateLayoutHandler != null)
                OnUpdateLayoutHandler(this, new EventArgs());
        }
        /// <summary>
        /// send form closing event
        /// </summary>
        protected void OnFormClosing()
        {
            if (OnFormClosingHandler != null)
                OnFormClosingHandler(this, new EventArgs());
        }
        /// <summary>
        /// send update layout collections event
        /// </summary>
        protected void OnUpdateLayoutCollections()
        {
            if (OnUpdateLayoutCollectionsHandler != null)
            {
                OnUpdateLayoutCollectionsHandler(this, new EventArgs());
            }
        }
        #endregion

        #region fields

        //ContextMenu
        private ToolStripSeparator _separator = new ToolStripSeparator();
        private ToolStripMenuItem _simItem;
        private ToolStripMenuItem _animalItem;
        private ToolStripMenuItem _householdItem;
        private ToolStripMenuItem _lotOccItem;
        private ToolStripMenuItem _lotResItem;
        private ToolStripMenuItem _lotComItem;
        private ToolStripMenuItem _patternItem;
        private ToolStripMenuItem _presetItem;
        private ToolStripMenuItem _coatsetItem;
        private ToolStripMenuItem _worldItem;

        private ILayoutCollection _currentLayoutCollection = null;
        private ILayout _currentLayout = null;

        private List<ILayoutCollection> _layoutCollectionList;

        #endregion

        #region properties

        /// <summary>
        /// all layout collections
        /// </summary>
        public List<ILayoutCollection> LayoutCollections
        {
            get
            {
                return _layoutCollectionList;
            }
            set
            {
                _layoutCollectionList = value;
            }
        }
        #endregion

        #region constructor

        /// <summary>
        /// constructor
        /// saves given layout collections in an intern list
        /// associates the layout collection list with the combobox
        /// activates the choosen layout type
        /// fills the context menues
        /// </summary>
        /// <param name="layoutCollections">list of all layout collections</param>
        /// <param name="layoutType">initial layout type</param>
        public EditReadmeLayoutGui(List<ILayoutCollection> layoutCollections, LayoutTypes layoutType)
        {
            InitializeComponent();

            _layoutCollectionList = layoutCollections;
            tsComboBoxLayoutCollections.ComboBox.DataSource = _layoutCollectionList;

            selectLayoutOfType(layoutType);

            fillKontextMenues();

            tsComboBoxLayoutCollections.Width = 210;
            tsComboBoxLayoutType.Width = 190;
        }

        #endregion

        #region methods

        #region fill kontext menues

        /// <summary>
        /// sets up the context menues
        /// </summary>
        private void fillKontextMenues()
        {
           
            fillContextMenue(names.layoutContextMenuSim, out _simItem, contextMenuMarkSim);
            fillContextMenue(names.layoutContextMenuAnimal, out _animalItem, contextMenuMarkAnimal);
            fillContextMenue(names.layoutContextMenuHousehold, out _householdItem, contextMenuMarkHousehold);
            fillContextMenue(names.layoutContextMenuResLot, out _lotResItem, contextMenuMarkLotRes);
            fillContextMenue(names.layoutContextMenuResLotOcc, out _lotOccItem, contextMenuMarkLotOccupied);
            fillContextMenue(names.layoutContextMenuComLot, out _lotComItem, contextMenuMarkLotCom);
            fillContextMenue(names.layoutContextMenuCoatset, out _coatsetItem, contextMenuMarkCoatset);
            fillContextMenue(names.layoutContextMenuPattern, out _patternItem, contextMenuPattern);
            fillContextMenue(names.layoutContextMenuPreset, out _presetItem, contextMenuMarkPreset);
            fillContextMenue(names.layoutContextMenuWorld, out _worldItem, contextMenuMarkWorld);

        }

        /// <summary>
        /// adds all menu items from a source menue to a parent menue item
        /// </summary>
        /// <param name="menueId">menue id</param>
        /// <param name="parentItem">parent menue item</param>
        /// <param name="sourceMenue">source menue</param>
        private void fillContextMenue(string menueId, out ToolStripMenuItem parentItem, ContextMenuStrip sourceMenue)
        {
            parentItem = new ToolStripMenuItem();
            parentItem.Name = menueId;
            parentItem.Text = menueId;

            int itemCount = 0;
            
            //get items from source menue
            ToolStripItemCollection itemCollection = sourceMenue.Items;
            
            itemCount = sourceMenue.Items.Count;
            for (int i = 0; i < itemCount; i++)
            {
                parentItem.DropDownItems.Add(itemCollection[0]);
            }
            
        }
        #endregion      

        #region button click

        /// <summary>
        /// when ok button clicked
        /// save current layout
        /// close form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btOk_Click(object sender, EventArgs e)
        {
            saveReadmeLayout();
            this.Close();
        }

        /// <summary>
        /// form is closed when cancel button is pushed
        /// not committed changes aren's saved
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// reacts if commit is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btCommit_Click(object sender, EventArgs e)
        {
            saveReadmeLayout();
        }

        /// <summary>
        /// Loads layout from a text file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btLoadLayout_Click(object sender, EventArgs e)
        {
            DialogResult result = openFileLayout.ShowDialog();
            if (result == DialogResult.OK)
            {
                try
                {
                    StreamReader myFile = new StreamReader(openFileLayout.FileName, System.Text.Encoding.UTF8);
                    txtLayoutText.Text = myFile.ReadToEnd();
                    myFile.Close();
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message);
                }

            }
        }

        /// <summary>
        /// saves current layout to a text file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btSaveLayout_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult result = saveFileLayout.ShowDialog();
                if (result == DialogResult.OK)
                {
                    StreamWriter myFile = new StreamWriter(saveFileLayout.FileName);
                    myFile.Write(txtLayoutText.Text);
                    myFile.Close();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }

        /// <summary>
        /// handles click on the edit layout collection button
        /// shows the edit layout collection dialog
        /// after editing the same layout collection gets selected again
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btEditLayoutCollection_Click(object sender, EventArgs e)
        {
            int selectedIndex = tsComboBoxLayoutCollections.SelectedIndex;

            EditLayoutCollectionGui editLayoutForm = new EditLayoutCollectionGui(_currentLayoutCollection);
            editLayoutForm.Text = names.layoutFormTitleEdit;

            if (editLayoutForm.ShowDialog() == DialogResult.OK)
            {
                //update the combobox
                tsComboBoxLayoutCollections.ComboBox.DataSource = null;
                tsComboBoxLayoutCollections.ComboBox.DataSource = _layoutCollectionList;
                OnUpdateLayoutCollections();
            }

            tsComboBoxLayoutCollections.SelectedIndex = selectedIndex;
        }

        /// <summary>
        /// handles the click on the new layout button
        /// shows the new layout collection dialog
        /// the new layout collection is appended in the list
        /// and selected in the combobox
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btNewLayoutCollection_Click(object sender, EventArgs e)
        {
            EditLayoutCollectionGui newLayoutForm = new EditLayoutCollectionGui();
            newLayoutForm.Text = names.layoutFormTitleNew;

            if (newLayoutForm.ShowDialog() == DialogResult.OK)
            {
                //add new layout collection
                _layoutCollectionList.Add(newLayoutForm.LayoutCollection);

                //update the combobox
                tsComboBoxLayoutCollections.ComboBox.DataSource = null;
                tsComboBoxLayoutCollections.ComboBox.DataSource = _layoutCollectionList;
                tsComboBoxLayoutCollections.SelectedIndex = tsComboBoxLayoutCollections.Items.Count - 1;

                OnUpdateLayoutCollections();
            }
        }

        /// <summary>
        /// handles the delete layout collection button
        /// before layout collection is deleted, ask for confirmation
        /// the new selected layout collection is the first standard collection
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btDeleteLayoutCollection_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show(string.Format(messages.messageDeleteLayoutCollection, _currentLayoutCollection.Name),
                                                    messages.messageDeleteLayoutCollectionTitle,
                                                    MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                //remove current Layout collection from list
                _layoutCollectionList.Remove(_currentLayoutCollection);
                ((CustomLayoutCollection)_currentLayoutCollection).Remove();

                //set current collection to first standard collection (can't be deleted)
                _currentLayoutCollection = _layoutCollectionList[0];

                //update the combobox
                tsComboBoxLayoutCollections.ComboBox.DataSource = null;
                tsComboBoxLayoutCollections.ComboBox.DataSource = _layoutCollectionList;
                tsComboBoxLayoutCollections.SelectedIndex = 0;

                OnUpdateLayoutCollections();
            }
        }

        #endregion
        
        #region gui changed (selectedIndex, text, ...)

        /// <summary>
        /// checks for current changes and ask for committing these
        /// sets new datasource of layout types combo box
        /// sets language info string
        /// searches the same layout type in the new layout collection
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsComboBoxLayoutCollections_SelectedIndexChanged(object sender, EventArgs e)
        {
            LayoutTypes layoutType = LayoutTypes.common;

            //get the old layout typ
            if (_currentLayout!=null)
            {
                layoutType = _currentLayout.LayoutType;
            }
            
            
            if (this.btCommit.Enabled == true)
            {
                checkIfSaveCurrentLayout();
            }

            updateCurrentLayoutCollection();

            if (_currentLayoutCollection != null)
            {
                //only custom layout collections can be deleted
                if (_currentLayoutCollection.GetType() == typeof(StandardLayoutCollection))
                {
                    btDeleteLayoutCollection.Enabled = false;
                }
                else
                {
                    btDeleteLayoutCollection.Enabled = true;
                }
                
                tsComboBoxLayoutType.ComboBox.DataSource = _currentLayoutCollection.GetLayouts();
                tsLabelLanguage.Text = _currentLayoutCollection.GetLayoutLanguageString();
            
                //in the new layout collection select layout of the same type
                if (_currentLayout!=null)
                {
                    selectLayoutOfType(layoutType);
                }

            }
            
            
        }

        /// <summary>
        /// checks for current changes and asks for commiting these
        /// updates the current layout and sets the new text of the layout textbox
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsComboBoxLayoutType_SelectedIndexChanged(object sender, EventArgs e)
        {
            
            if (this.btCommit.Enabled == true)
            {
                checkIfSaveCurrentLayout();
            }

            updateCurrentLayout();
                    
            txtLayoutText.Text = _currentLayout.LayoutText;
        }

        /// <summary>
        ///compares text from the layout object with new text in the textbox
        ///when they are different the commit button is enabled
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtLayoutText_TextChanged(object sender, EventArgs e)
        {
            ILayout layout = tsComboBoxLayoutType.SelectedItem as ILayout;
            if (layout != null)
            {
                string textOld = layout.LayoutText;
                string textNew = txtLayoutText.Text;

                if (textOld.CompareTo(textNew) != 0)
                {
                    //when texts are different, enable commit button
                    btCommit.Enabled = true;
                }
                else
                {
                    btCommit.Enabled = false;
                }
            }

        }

        /// <summary>
        /// Handles the Form Closing Event
        /// Sends itself a closing event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EditReadmeLayoutGui_FormClosing(object sender, FormClosingEventArgs e)
        {
            OnFormClosing();
        }

        #endregion

        #region layout methods

        /// <summary>
        /// selects the layout of the given type in the combobox
        /// </summary>
        /// <param name="layoutType"></param>
        private void selectLayoutOfType(LayoutTypes layoutType)
        {

            if (tsComboBoxLayoutCollections.SelectedItem!=null)
            {
                int index = 0;
                foreach (ILayout layout in ((ILayoutCollection)tsComboBoxLayoutCollections.SelectedItem).GetLayouts())
                {

                    if (layout.LayoutType == layoutType)
                    {
                        tsComboBoxLayoutType.SelectedIndex = index;
                    }

                    index++;
                }
            }
            
        }
       
        /// <summary>
        /// displays message box
        /// and saves current layout when answer is yes
        /// </summary>
        private void checkIfSaveCurrentLayout()
        {
            DialogResult result = MessageBox.Show(  messages.messageSaveLayoutChanges, 
                                                    messages.messageSaveLayoutChangesTitle, 
                                                    MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                saveReadmeLayout();                    
            }
        }
        /// <summary>
        /// keeps the current layout collection
        /// </summary>
        private void updateCurrentLayoutCollection()
        {
            _currentLayoutCollection = (ILayoutCollection)tsComboBoxLayoutCollections.SelectedItem;
        }
        /// <summary>
        /// keeps the current layout
        /// </summary>
        private void updateCurrentLayout()
        {
            _currentLayout = (ILayout)tsComboBoxLayoutType.SelectedItem;            
        }
        /// <summary>
        ///saves the text of the layout textfield in the current layout
        /// </summary>
        private void saveReadmeLayout()
        {
            _currentLayout.LayoutText = txtLayoutText.Text;
            _currentLayoutCollection.Save();
            btCommit.Enabled = false;
            OnLayoutUpdate();
        }

        #endregion

        #region context menu

        #region context menu click        

        private void menuItemCommonListPackNames_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markListPackages);
        }

        private void menuItemCommonListPackCreatorHp_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markListPackagesDetails);
        }

        private void menuItemSimSpecies_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimSpecies);
        }

        private void menuItemHouseholdSimSpecies_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimSpecies);
        }

        private void menuItemLotOccHSimSpecies_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimSpecies);
        }
        private void menuItemCommonCreator_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markCreator);
        }

        private void menuItemCommonHomepage_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markHomepage);
        }

        private void menuItemCommonName_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markDisplayName);
        }

        private void menuItemCommonDescription_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markDescription);
        }

        private void menuItemCommonType_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markType);
        }

        private void menuItemCommeGameversion_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markGameVersion);
        }

        private void menuItemCommonPackageId_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markPackageId);
        }

        private void menuItemCommonListStuff_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markListStuffpacks);
        }

        private void menuItemCommonListExpansions_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markListExtensions);
        }

        private void menuItemCommonListStore_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markListStoreItems);
        }

        private void menuItemSimName_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimName);
        }

        private void menuItemSimDescription_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimDescription);
        }

        private void menuItemSimBiography_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimBio);
        }

        private void menuItemSimAge_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimAge);
        }

        private void menuItemSimGender_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimGender);
        }

        private void menuItemFavFood_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimFavFood);
        }

        private void menuItemFavMusic_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimMusic);
        }

        private void menuItemFavColor_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimColor);
        }

        private void menuItemFavList_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimListFavs);
        }

        private void menuItemTraitList_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimListTraits);
        }

        private void menuItemHouseholdName_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markHouseholdName);
        }

        private void menuItemHouseholdBiography_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markHouseholdBio);
        }

        private void menuItemHouseholdFunds_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markHouseholdFunds);
        }

        private void menuItemHouseholdSimSecStart_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimsSectionStart);
        }

        private void menuItemHouseholdSimSecEnd_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimsSectionEnd);
        }

        private void menuItemHouseholdSimName_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimName);
        }

        private void menuItemHouseholdSimAge_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimAge);
        }

        private void menuItemHouseholdSimGender_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimGender);
        }

        private void menuItemHouseholdSimBiography_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimBio);
        }

        private void menuItemLotOccName_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markLotName);
        }

        private void menuItemLotOccDescr_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markLotDescription);
        }

        private void menuItemLotOccType_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markLotResidentialType);
        }

        private void menuItemLotOccSize_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markLotSize);
        }

        private void menuItemLotOccMaxLevel_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markLotMaxLevel);
        }

        private void menuItemLotOccMinLevel_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markLotMinLevel);
        }

        private void menuItemLotOccHousehName_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markHouseholdName);
        }

        private void menuItemLotOccHousehFunds_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markHouseholdFunds);
        }

        private void menuItemLotOccHousehBiography_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markHouseholdBio);
        }

        private void menuItemLotOccHSimSecStart_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimsSectionStart);
        }

        private void menuItemLotOccHSimSecEnd_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimsSectionEnd);
        }

        private void menuItemLotOccHSimName_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimName);
        }

        private void menuItemLotOccHSimAge_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimAge);
        }

        private void menuItemLotOccHSimGender_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimGender);
        }

        private void menuItemLotOccHSimBiography_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimBio);
        }

        private void menuItemLotResName_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markLotName);
        }

        private void menuItemLotResDesrc_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markLotDescription);
        }

        private void menuItemLotResType_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markLotResidentialType);
        }

        private void menuItemLotResSize_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markLotSize);
        }

        private void menuItemLotResMaxLevel_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markLotMaxLevel);
        }

        private void menuItemLotResMinLevel_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markLotMinLevel);
        }

        private void menuItemLotComName_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markLotName);
        }

        private void menuItemLotComDesc_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markLotDescription);
        }

        private void menuItemLotComType_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markLotCommunityType);
        }

        private void menuItemLotComSize_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markLotSize);
        }

        private void menuItemLotComMaxLevel_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markLotMaxLevel);
        }

        private void menuItemLotComMinLevel_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markLotMinLevel);
        }

        private void menuItemCoatsetAge_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markCoatsetAge);
        }

        private void menuItemCoatsetSpecies_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markCoatsetSpecies);
        }

        private void menuItemPresetAge_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markPresetAge);
        }

        private void menuItemPresetGender_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markPresetGender);
        }

        private void menuItemPatternCategory_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markPatternCategory);
        }

        private void menuItemWorldSize_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markWorldSize);
        }

        private void menuItemWolrdLotNo_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markWorldNoLots);
        }

        private void menuItemWolrdLotComNo_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markWorldNumComLots);
        }

        private void menuItemWorldLotResNo_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markWorldNumResLots);
        }

        private void menuItemWorldLotOccNo_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markWorldNumOccLots);
        }

        private void menuItemWorldSimsNo_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markWorldNumWorldSims);
        }

        private void menuItemAnimalName_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimName);
        }

        private void menuItemAnimalDescr_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimDescription);
        }

        private void menuItemAnimalBio_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimBio);
        }

        private void menuItemAnimalAge_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimAge);
        }

        private void menuItemAnimalSpecies_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimSpecies);
        }

        private void menuItemAnimalGender_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimGender);
        }

        private void menuItemAnimalListTraits_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markSimListTraits);
        }
        private void namesOnlyVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markListPackagesVert);
        }

        private void withCreatorHPVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markListPackagesDetVert);
        }

        private void linkSequentiellPackageToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markListPackagesLinks);
        }

        private void linkVerticalPackageToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markListPackagesLinkVE);
        }

        private void namesSequentiellAddonToolStripMenuItem_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markListExtensions);
        }

        private void namesVerticalAddonToolStripMenuItem_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markListExtensionsVert);
        }

        private void onlyAbbrevAddonToolStripMenuItem_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markListExtensionsAbbr);
        }

        private void namesSequentiellStufffortlaufendToolStripMenuItem_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markListStuffpacks);
        }

        private void NamesVerticalStuffToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markListStuffpacksVert);
        }

        private void onlyAbbrevStuffToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markListStuffpacksAbbr);
        }

        private void namesSequentiellToolStripMenuItem_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markListStoreItems);
        }

        private void namesVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markListStoreItemsVert);
        }

        private void linkSequentiellToolStripMenuItem_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markListStoreItemsLink);
        }

        private void linkVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markListStoreItemsLinVe);
        }

        private void menuItemCommonListPackNames_Click_1(object sender, EventArgs e)
        {
            insertMark(layoutMarks.markListPackages);
        }
        
        #endregion

        /// <summary>
        /// sets the context sub menue fpr the current layout type
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void contextMenuMarkCommon_Opening(object sender, CancelEventArgs e)
        {
            contextMenuMarkCommon.Items.Remove(_separator);
            contextMenuMarkCommon.Items.Remove(_simItem);
            contextMenuMarkCommon.Items.Remove(_animalItem);
            contextMenuMarkCommon.Items.Remove(_householdItem);
            contextMenuMarkCommon.Items.Remove(_lotOccItem);
            contextMenuMarkCommon.Items.Remove(_lotResItem);
            contextMenuMarkCommon.Items.Remove(_lotComItem);
            contextMenuMarkCommon.Items.Remove(_coatsetItem);
            contextMenuMarkCommon.Items.Remove(_patternItem);
            contextMenuMarkCommon.Items.Remove(_presetItem);
            contextMenuMarkCommon.Items.Remove(_worldItem);
                
            
            if (_currentLayout != null)
            {
                switch (_currentLayout.LayoutType)
                {
                    case LayoutTypes.sim:                    
                        contextMenuMarkCommon.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { _separator, _simItem });
                        break;
                    case LayoutTypes.animal:
                        contextMenuMarkCommon.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { _separator, _animalItem });
                        break;
                    case LayoutTypes.household:
                        contextMenuMarkCommon.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { _separator, _householdItem });
                        break;
                    case LayoutTypes.reslot:
                        contextMenuMarkCommon.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { _separator, _lotResItem });
                        break;
                    case LayoutTypes.reslotocc:
                        contextMenuMarkCommon.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { _separator, _lotOccItem });
                        break;
                    case LayoutTypes.comlot:
                        contextMenuMarkCommon.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { _separator, _lotComItem });
                        break;
                    case LayoutTypes.world:
                        contextMenuMarkCommon.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { _separator, _worldItem });
                        break;
                    case LayoutTypes.preset:
                        contextMenuMarkCommon.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { _separator, _presetItem });
                        break;
                    case LayoutTypes.coatset:
                        contextMenuMarkCommon.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { _separator, _coatsetItem });
                        break;
                    case LayoutTypes.pattern:
                        contextMenuMarkCommon.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { _separator, _patternItem });
                        break;
                    default:
                        break;
                }                
            }
        }

        /// <summary>
        /// inserts a string at the current cursor position in the layout text box
        /// </summary>
        /// <param name="mark"></param>
        private void insertMark(string mark)
        {
            int newCursorPosition = txtLayoutText.SelectionStart + mark.Length;
            txtLayoutText.Text = txtLayoutText.Text.Insert(txtLayoutText.SelectionStart, mark);
            txtLayoutText.SelectionStart = newCursorPosition;
        }

        #endregion      

        

        #endregion

    
    }
}
